package com.ycdx.impms.action;

import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.ycdx.impms.impl.MeterImpl;
import com.ycdx.impms.pojo.Meter;

public class ExportMeterInfoAction extends ActionSupport{
	
	private static final long serialVersionUID = -8109981414099204475L;
	private List<Meter> allMeter;
	private String area;
	private InputStream excelStream;
	private String fileName = null;
	ActionContext ctx = ActionContext.getContext(); 
    HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);       
    HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE); 
	

	public InputStream getExcelStream() {
		allMeter = MeterImpl.queryByArea(area);	
		//System.out.println(RyxxImpl.getExcelStream(allRyxx));
		return MeterImpl.getExcelStream(allMeter);	
	}
	
	public String getFileName() {	   	 
        try {
        	response.setHeader("charset","ISO8859-1");  
        	fileName = this.area + "FTTH工具仪表信息.xls";
			return new String(this.fileName.getBytes(),"ISO8859-1");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "获取文件名出现了错误!";
		} 	       
	}
	
	public String execute(){
		//System.out.println(area);
		return SUCCESS;
	}

	public String getArea() {
		return area;
	}

	public void setArea(String area) {
		this.area = area;
	}
}
